package com.css.fxfzxczh.modules.report.service.impl;

import com.css.fxfzxczh.constants.YNEnum;
import com.css.fxfzxczh.modules.report.entity.ReportTemplate;
import com.css.fxfzxczh.modules.report.repository.ReportTemplateRepository;
import com.css.fxfzxczh.modules.report.service.ReportTemplateService;
import com.css.fxfzxczh.util.CreateGson;
import com.css.fxfzxczh.util.PlatformDateUtils;
import com.css.fxfzxczh.util.PlatformSessionUtils;
import com.css.fxfzxczh.util.UUIDGenerator;
import com.css.fxfzxczh.zcpt.sys.entity.SUser;
import com.css.fxfzxczh.zcpt.sys.service.SUserService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ReportTemplateServiceImpl implements ReportTemplateService {
    @Autowired
    private ReportTemplateRepository reportTemplateRepository;
    @Autowired
    private SUserService sUserService;
    @Override
    public void save(ReportTemplate reportTemplate) {
        reportTemplate.setId(UUIDGenerator.getUUID());
        reportTemplate.setCreateUserId(PlatformSessionUtils.getUserId());
        reportTemplate.setDelFlag(YNEnum.N.toString());
        String sUser1 = sUserService.getSUser(PlatformSessionUtils.getUserId());
        SUser sUser = CreateGson.createGson().fromJson(sUser1, SUser.class);
        reportTemplate.setUnit(sUser.getOrgName());
        reportTemplateRepository.save(reportTemplate);
    }

    @Override
    public String getNumber() {
        return "BGMB01";
    }

    @Override
    public List<ReportTemplate> getList() {
        return reportTemplateRepository.getList();
    }

    @Override
    public void updateTemplate(ReportTemplate reportTemplate) {
        reportTemplate.setUpdateUserId(PlatformSessionUtils.getUserId());
        reportTemplate.setUpdateTime(PlatformDateUtils.getCurrentTimestamp());
        reportTemplateRepository.updateTemplate(reportTemplate);
    }
}
